import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:ball_lion/module/match/detail/lq_odds_detail_logic.dart';
import 'package:ball_lion/resources/colours.dart';
import 'package:ball_lion/resources/styles.dart';
import 'package:ball_lion/utils/date_time_utils.dart';
import 'package:ball_lion/utils/utils.dart';
import 'package:ball_lion/utils/widget_utils.dart';
import 'package:ball_lion/module/record/items/data_left_list.dart';
import 'package:ball_lion/widgets/loading/loading_widget.dart';

import 'package:ball_lion/widgets/base/wqs_text.dart';

class LqOddsDetailView extends StatelessWidget {
  LqOddsDetailView({Key? key}) : super(key: key);

  final logic = Get.put(LqOddsDetailLogic());
  @override
  Widget build(BuildContext context) {
    return GetBuilder<LqOddsDetailLogic>(builder: (controller) {
      return Scaffold(
          backgroundColor: Colours.main,
          appBar: Styles.appBar(
              backgroundColor: Colours.main,
              titleTextStyle:
                  const TextStyle(fontSize: 14, color: Colours.white),
              title: SizedBox(
                width: MediaQuery.of(context).size.width - 140,
                child:
                    Row(mainAxisAlignment: MainAxisAlignment.center, children: [
                  Expanded(
                      child: QsText(
                    controller.detail.detail?.awayTeamName ?? "",
                  ).alignEnd),
                  QsText(" vs "),
                  Expanded(
                      child: QsText(
                    controller.detail.detail?.homeTeamName ?? "",
                  ).alignStart)
                ]),
              ),
              leadingColor: Colours.white),
          body: Container(
            clipBehavior: Clip.antiAlias,
            decoration: const BoxDecoration(
                color: Colours.white,
                borderRadius: BorderRadius.only(
                    topRight: Radius.circular(10),
                    topLeft: Radius.circular(10))),
            child: Column(
              children: [
                // SizedBox(
                //   height: 40,
                //   width: double.infinity,
                //   child: TabBar(
                //     controller: controller.tabController,
                //     tabs: List.generate(controller.typeList.length,
                //         (index) => Tab(text: controller.typeList[index])),
                //     indicator: const CustomIndicator(
                //         borderSide: BorderSide(width: 2, color: Colours.blue2766D6),
                //         indicatorBottom: 1,
                //         indicatorWidth: 15),
                //     labelColor: Colours.blue2766D6,
                //     labelPadding: const EdgeInsets.symmetric(horizontal: 5),
                //     unselectedLabelColor: Colours.grey66,
                //     labelStyle: const TextStyle(
                //         fontSize: 16, fontWeight: FontWeight.w500),
                //     unselectedLabelStyle: const TextStyle(fontSize: 16),
                //     onTap: (value) {
                //       controller.typeIndex = value;
                //     },
                //   ),
                // ),
                Expanded(
                  child: TabBarView(
                      physics: const NeverScrollableScrollPhysics(),
                      controller: controller.tabController,
                      children: List.generate(
                          controller.typeList.length,
                          (index) => LoadingWidget<int>(
                                isLoading: false,
                                data: controller.companies[index].length,
                                child: () => Row(
                                  children: [
                                    DataLeftList(
                                        controller.companies[index]
                                            .map((e) => e.name ?? "")
                                            .toList(),
                                        controller.selectIndex[index], (p0) {
                                      controller.setSelectIndex(index, p0);
                                      controller.requestData(p0);
                                    }).paddingOnly(top: 16),
                                    Expanded(child: rightPage(index))
                                  ],
                                ),
                              ))),
                )
              ],
            ),
          ));
    });
  }

  Widget rightPage(int i) {
    return Column(
      children: [
        DefaultTextStyle(
          style: const TextStyle(fontSize: 12, color: Colours.grey66),
          child: Container(
            height: 40,
            padding: const EdgeInsets.symmetric(horizontal: 16),
            child: Row(
              children: [
                Expanded(
                    flex: 2, child: QsText(logic.headTypeList[i][0]).center),
                if (i == 0) Expanded(flex: 2, child: Container()),
                Expanded(
                    flex: 2, child: QsText(logic.headTypeList[i][1]).center),
                if (i != 0)
                  Expanded(
                      flex: 2, child: QsText(logic.headTypeList[i][2]).center),
                Expanded(
                    flex: 1,
                    child: QsText("时", color: Colours.transparent).center),
                Expanded(flex: 3, child: QsText("时间").center)
              ],
            ).paddingSymmetric(horizontal: 16),
          ),
        ),
        Expanded(
          child: LoadingWidget<int>(
            isLoading: false,
            data: logic.data[i].length,
            child: () => SingleChildScrollView(
                physics: const ClampingScrollPhysics(),
                child: Column(
                  children: List.generate(logic.data[i].length, (index) {
                    var entity = logic.data[i][index];
                    var data =
                        logic.formSingleLine(logic.data[i][index].data ?? []);
                    return Stack(
                      children: [
                        Container(
                          height: 44,
                          margin: const EdgeInsets.symmetric(horizontal: 16),
                          decoration: const BoxDecoration(
                              border: Border(
                                  bottom: BorderSide(
                                      color: Colours.greyEE, width: 0.5))),
                          child: Row(
                            children: [
                              Expanded(
                                  flex: 2,
                                  child: (entity.closed == "封"
                                          ? QsText("-", fontSize: 12)
                                          : data[0])
                                      .center),
                              Expanded(
                                  flex: 2,
                                  child: (i == 1 || i == 2
                                          ? QsText(
                                              entity.closed == "封"
                                                  ? "封"
                                                  : entity.line ?? "",
                                              fontSize: 12)
                                          : entity.closed == "封"
                                              ? QsText("封", fontSize: 12)
                                              : data[1])
                                      .center),
                              Expanded(
                                  flex: 2,
                                  child: (entity.closed == "封"
                                          ? QsText("-", fontSize: 12)
                                          : data[2])
                                      .center),
                              Expanded(
                                  flex: 1,
                                  child: Stack(
                                    children: [
                                      SizedBox(
                                          height: Get.height,
                                          child: QsText("时",
                                                  fontSize: 12,
                                                  color: Colors.transparent)
                                              .center),
                                      if (entity.beginFlag == true)
                                        Positioned(
                                            child: Image.asset(Utils.getImgPath(
                                                "odds_match_begin.png")))
                                    ],
                                  )),
                              Expanded(
                                  flex: 3,
                                  child: QsText(
                                          entity.updateTime.noValue == true
                                              ? ""
                                              : DateTime.parse(
                                                      entity.updateTime!)
                                                  .formatedString(
                                                      "MM/dd HH:mm"),
                                          fontSize: 12,
                                          color: Colours.grey99)
                                      .center)
                            ],
                          ),
                        ),
                        if (entity.beginFlag == true)
                          Align(
                              alignment: Alignment.topCenter,
                              child: _beginFlag())
                      ],
                    );
                  }),
                ).paddingOnly(bottom: 50)),
          ),
        )
      ],
    );
  }

  Widget _beginFlag() {
    return Container(
      height: 14,
      width: 36,
      alignment: Alignment.center,
      decoration: const BoxDecoration(
          color: Colours.main,
          borderRadius: BorderRadius.vertical(bottom: Radius.circular(4))),
      child: QsText("赛前", color: Colours.white, fontSize: 10),
    );
  }
}
